/***
 * * PROJECT
 * *    ATaG
 * * VERSION
 * *    $Revision: 1.1 $
 * * DATE
 * *    $Date: 2007/02/02 11:23:58 $
 * * LOG
 * *    $Log: HVACTopologyGenerator.java,v $
 * *    Revision 1.1  2007/02/02 11:23:58  lmottola
 * *    Benchmarking code for compiler in.
 * *
 * * 
 * *   ATaG (Abstract Task Graph) - Data-driven Macroprogramming for
 * *                                Sensor Networks
 * *
 * *
 * *   This program is free software; you can redistribute it and/or
 * *   modify it under the terms of the GNU General Public License
 * *   as published by the Free Software Foundation; either version 2
 * *   of the License, or (at your option) any later version.
 * *
 * *   This program is distributed in the hope that it will be useful,
 * *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * *   GNU General Public License for more details.
 * *
 * *   You should have received a copy of the GNU General Public License
 * *   along with this program; if not, you may find a copy at the FSF web
 * *   site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
 * *   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * *   Boston, MA  02111-1307, USA
 ***/

package atag.apps.hvac;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class HVACTopologyGenerator {

	public static final int COMM_RANGE = 620;

	public static final int SENSE_RANGE = 310;

	public static final int HVAC_NODES = 2;

	public static final double SCALING_FACTOR = 0.6;

	public static final int SIM_AREA = 10000;

	private static final int RANDOM_SEED = 12345;

	private static int nextNodeId;

	public static List<String> generateTopology(int commRange,
			double scalingFactor, int nHVAC, int simArea) {

		Random rnd = new Random(RANDOM_SEED);
		LinkedList<String> nodes = new LinkedList<String>();
		nextNodeId = 0;
		String n1, n2;
		int gridFactor = (int) (scalingFactor * commRange);

		// Generating Temperature/Humdity sensors (in a grid)
		for (int x = 0; x < simArea; x += gridFactor) {

			if ((nextNodeId /2) % 2 == 0) {
				n1 = nextNodeId + " " + x
						+ " 0 Floor:0 attachedSensors:TemperatureSensor\n";
				nextNodeId++;
				n2 = nextNodeId + " " + x + " " + gridFactor
						+ " Floor:0 attachedSensors:HumiditySensor\n";
			} else {
				n1 = nextNodeId + " " + x
						+ " 0 Floor:0 attachedSensors:HumiditySensor\n";
				nextNodeId++;
				n2 = nextNodeId + " " + x + " " + gridFactor
						+ " Floor:0 attachedSensors:TemperatureSensor\n";
			}
			nodes.add(n1);
			nodes.add(n2);
			nextNodeId++;
		}

		// Generating routing nodes (in a line)
		int maxY = gridFactor * 2;
		for (int x = 0; x < simArea; x += gridFactor) {

			String n = nextNodeId + " " + x + " " + maxY
					+ " Floor:0 attachedSensors:none\n";
			nodes.add(n);
			nextNodeId++;
		}

		// Generating HVAC nodes (randomly placed)
		for (int i = 0; i < nHVAC; i++) {
			int x = rnd.nextInt(simArea);
			int y = rnd.nextInt(maxY);
			String n = nextNodeId + " " + x + " " + y
					+ " Floor:0 attachedActuators:HVAC\n";
			nodes.add(n);
			nextNodeId++;
		}

		nodes.addFirst(nextNodeId + " " + simArea + " " + simArea + " "
				+ commRange + " " + (commRange / 2) + "\n");
		return nodes;

	}
}
